# valid braket

import re

brakets = input()

list = re.findall('[()]{1}', brakets) # 先提取出所有的括号

def braketl(list): # 左计数函数
    len = bra = ket = 0
    for i in list:
        if i == '(':
            bra += 1
        else:
            ket += 1
        if bra == ket:
            len = max(len, bra + ket)
        elif bra < ket:
            bra = ket = 0
    return len

def braketr(list): # 反向计数函数, 因为有可能出现bra一直大于ket的情况
    len = bra = ket = 0
    for i in list:
        if i == '(':
            bra += 1
        else:
            ket += 1
        if bra == ket:
            len = max(len, bra + ket)
        elif bra > ket:
            bra = ket = 0
    return len

print(max(braketl(list), braketr(list[::-1])))